﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IDateTimePicker</summary>
	public class IDateTimePicker : System.Windows.Forms.DateTimePicker
	{
        /// <summary>Property: Value</summary>
        public new DateTime Value
        {
            get
            {
                return Checked ? base.Value : DateTime.MinValue;
            }
            set
            {
                if (!ShowCheckBox) base.Value = value;
                else
                {
                    bool B = value != DateTime.MinValue;
                    if (B) // Nastavit hodnotu?
                    {
                        Checked = true;
                        base.Value = value;
                    }
                    else
                    {
                        base.Value = DateTime.Now;
                        Checked = false;
                    }
                }
            }
        }

        /// <summary>Konstruktor</summary>
        /// <param name="pUseCheckbox">priznak pouzitia checkboxu</param>
        /// <param name="pCustomFormat">vlastny format</param>
        public IDateTimePicker(bool pUseCheckbox = true, string pCustomFormat = null)
        {
            if (!string.IsNullOrEmpty(pCustomFormat)) // Nastavim custom format?
            {
                CustomFormat = pCustomFormat; Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            }
            ShowCheckBox = pUseCheckbox; // Nastavim priznak
        }
	}
}
